import requests
import re


def get_article_statistics(article_id):
    url = "https://baijiahao.baidu.com/builderinner/open/resource/query/articleStatistics"

    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36",
    }

    data = {"app_id": "1689933945625238", "app_token": "84b4ca975911e2fcd36d9609dac0cda6", "article_id": article_id}

    response = requests.post(url=url, data=data, headers=headers)

    answer = response.content.decode()

    # {"data":{"recommend_count":570,"comment_count":0,"view_count":438,"share_count":0,"collect_count":0,"likes_count":0},"errno":0,"errmsg":"成功"}
    answer = re.findall(r'"data":(.+),"errno"', answer)[0]
    answer = eval(answer)

    answer1 = f'推荐量{answer["recommend_count"]}, 播放量{answer["view_count"]}'

    # print(answer1)
    return answer1


if __name__ == "__main__":
    article_id = input("输入文章id：")  # 3000386171819859503
    answer1 = get_article_statistics(article_id)
    print(answer1)
